﻿@model CreateHostViewModel
@{
	Layout = "../Shared/_InstallLayout.cshtml";
	ViewBag.Title = "CMS Host installation";
}
<div id="containernarrow">
	<h2>@ViewBag.Title</h2>

	@using (Html.BeginForm()) {
		@Html.AntiForgeryToken()
		@Html.HiddenFor(m => m.ShowPagesPrefix);
		@Html.HiddenFor(m => m.ShowMembershipTypeOptions);
		<fieldset>
			<legend>Host properties</legend>
			<div>
				<label>Local or remote data store</label>
				@Html.RadioButtonFor(m => m.LocalOrRemoteDatabase, "Local", new { id = "local", @class = "localremote" })
				<label for="local" class="inline">Local</label>
				@Html.RadioButtonFor(m => m.LocalOrRemoteDatabase, "Remote", new { id = "remote", @class = "localremote" })
				<label for="remote" class="inline">Remote</label>
			</div>
			<div id="datadir">
				@Html.LabelFor(m => m.DataDirectory, "Data directory (will be located in ~/App_Data/Cms/)")
				@Html.TextBoxFor(m => m.DataDirectory, new { @class = "te fe-max" })
				@Html.ValidationMessageFor(m => m.DataDirectory)
			</div>
			<div id="connectionstring">
				<div>
					@Html.LabelFor(m => m.ConnectionString, "Connection string")
					@Html.TextBoxFor(m => m.ConnectionString, new { @class = "te fe-max" })
					@Html.ValidationMessageFor(m => m.ConnectionString)
				</div>
				<div>
					@Html.LabelFor(m => m.DatabaseName, "Database name (optional)")
					@Html.TextBoxFor(m => m.DatabaseName, new { @class = "te fe-middle" })
					@Html.ValidationMessageFor(m => m.DatabaseName)
				</div>
			</div>
			@if (Model.ShowPagesPrefix) {
				<div>
					@Html.LabelFor(m => m.PagesPrefix, "Url prefix for content pages (for example 'pages')")
					@Html.TextBoxFor(m => m.PagesPrefix, new { @class = "te fe-small" })
					@Html.ValidationMessageFor(m => m.PagesPrefix)
				</div>
			}
			@if (Model.ShowMembershipTypeOptions) {
				<div>
					<label>Users and roles</label>
					@Html.RadioButtonFor(m => m.MembershipType, "Builtin", new { id = "builtin", @class = "membershiptype" })
					<label for="builtin" class="inline">Built-in</label>
					@Html.RadioButtonFor(m => m.MembershipType, "Membership", new { id = "membership", @class = "membershiptype" })
					<label for="membership" class="inline">ASP.NET Membership</label>
				</div>
				<div id="membershipoptions">
					<div>
						@Html.LabelFor(m => m.MembershipProvider, "Membership provider")
						@Html.DropDownListFor(m => m.MembershipProvider, new SelectList(Model.AvailableMembershipProviders, Model.MembershipProvider), new { @class = "te fe-max" })
					</div>
					<div>
						@Html.LabelFor(m => m.RoleProvider, "Role provider")
						@Html.DropDownListFor(m => m.RoleProvider, new SelectList(Model.AvailableRoleProviders, Model.RoleProvider), new { @class = "te fe-max" })
					</div>
				</div>
			}
		</fieldset>
		<input type="submit" value="Install" />
	}
</div>

<script type="text/javascript">
	$(document).ready(function () {
		setDataDirOrConnectionString();
		$('.localremote').change(function () {
			setDataDirOrConnectionString();
		});
		setMembershipOptions();
		$('.membershiptype').change(function () {
			setMembershipOptions();
		});
	});

	function setDataDirOrConnectionString() {
		if ($('#local:checked').length > 0) {
			$('#datadir').show();
			$('#connectionstring').hide();
		}
		else {
			$('#datadir').hide();
			$('#connectionstring').show();
		}
	}

	function setMembershipOptions() {
		if ($('#membership:checked').length > 0) {
			$('#membershipoptions').show();
		}
		else {
			$('#membershipoptions').hide();
		}
	}
</script>